package com.tul.exercise.base.java8.stream.base;

import com.tul.exercise.base.java8.common.Constant;
import com.tul.exercise.base.java8.util.BeanAtributeHelper;
import com.tul.exercise.base.utils.MathUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.List;

/**
 * 苹果类
 *
 * @author tuliang
 */
public class Apple {
    private static final int MAX_WEIGHT = 10000;
    private String name;

    private String color;

    private Double weight;
    public Apple () {

    }

    public Apple(String name) {
        this.name = name;
    }

    public Apple(String name, double weight) {
        this.name = name;
        this.weight = weight;
    }

    public Apple(String name, String color) {
        this.name = name;
        this.color = color;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

    /**
     * 创建Artist
     * @return Artist
     */
    public static Apple createApple() {
        Apple result = new Apple();
        result.setName(BeanAtributeHelper.getRandomItem(Constant.APPLE_NAMES));

        int weight = MathUtils.getRandomInt(100, MAX_WEIGHT);
        result.setWeight(Double.valueOf(weight));

        result.setColor(BeanAtributeHelper.getRandomItem(Constant.APPLE_COLOR));
        return result;
    }

    /**
     * 创建Apple列表
     * @param num 个数
     * @return List<Artist>
     */
    public static List<Apple> createApples(int num) {
        List<Apple> list = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            list.add(createApple());
        }
        return list;
    }
}
